package com.basic.model.quartz.param;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper=false)
public class TestTaskParam extends TaskParam{

    private final static String JOB_KEY = "TEST_KEY";

    @Data
    @EqualsAndHashCode(callSuper = false)
    public static class Body extends TaskParam.Body {
        private String key;
    }

    public TestTaskParam() {
        this(null, null);
    }

    public TestTaskParam(Body body) {
        this(null, body);
    }

    public TestTaskParam(Header header, Body body) {
        super(TaskType.TEST_TASK, header, body);
    }

    @Override
    public KeyBuilder getKeyBuilder() {
        return TaskParam.KeyBuilder.builder()
                                    .name(StrUtil.format("{}", getBodyFormat().getKey()))
                                    .group(JOB_KEY)
                                    .build();
    }

    @Override
    public Body getBodyFormat() {
        if (body != null) {
            return JSONObject.parseObject(body, Body.class);
        } else {
            return null;
        }
    }

    @Override
    public Integer getDelaySeconds() {
        return 1;
    }


}
